<template>
    <div class="unitTable">
        <div class="padding15All tableMain">
            <TableTop :type="type">
                <!-- <template v-slot:unit>
                    <el-button @click="dialogFormVisible = true" size="small" type="primary">添加个人</el-button>
                </template> -->
                <template v-slot:delete>
                    <el-button @click="edit" size="small" type="info">删除</el-button>
                </template>
            </TableTop>

            <el-table ref="multipleTable" :data="list" tooltip-effect="dark" style="width: 100%;height:100%;"
                @selection-change="handleSelectionChange" :empty-text='emtypetxt'>
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column fixed prop="userName" label="姓名" width="250">
                </el-table-column>
                <el-table-column prop="contactsEnterpriseName" label="所在企业" width="277">
                </el-table-column>
                <el-table-column prop="userPhone" label="手机号" width="250">
                </el-table-column>
                <el-table-column label="认证状态" width="200">
                    <template slot-scope="scope">
                        <el-tag size="small" v-if="scope.row.authType == 1" type="success">已认证</el-tag>
                        <el-tag size="small" v-if="scope.row.authType == 0" type="warning">未认证</el-tag>
                    </template>
                </el-table-column>
                <el-table-column v-if="type == 'companyDetail'" prop="e" label="相关合同" width="100">
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="320">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">详情</el-button>
                        <!-- <el-button @click="dialogFormVisible = true" type="text" size="small">编辑</el-button> -->
                        <el-button @click="edit" type="text" size="small">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="flexleft padding15" style="justify-content: flex-end;">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="params.pageNo" :page-sizes="[10, 20, 50, 100]" :page-size="params.pageSize"
                layout="total, prev, pager, next, sizes, jumper" :total="total">
            </el-pagination>
        </div>

        <el-dialog title="添加个人" :visible.sync="dialogFormVisible" width="560px">
            <el-form :model="form">
                <el-form-item required label="姓名" label-width="180px">
                    <el-input v-model="form.name" placeholder="请输入姓名" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item required label="手机号" label-width="180px">
                    <el-input v-model="form.name" placeholder="请输入手机号" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="所在企业" label-width="180px">
                    <el-select size="small" v-model="form.region" placeholder="请输入">
                        <el-option label="郑州盒蚌精选食品有限公司 " value="郑州盒蚌精选食品有限公司 "></el-option>
                        <el-option label="郑州盒蚌精选食品有限公司 " value="郑州盒蚌精选食品有限公司 "></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注" label-width="180px">
                    <el-input maxlength="200" type="textarea" v-model="form.name" placeholder="请输入备注" autocomplete="off"
                        show-word-limit></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">保存</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">保存并继续添加</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import TableTop from '../components/TableTop.vue'
import { oppositeListDetail, } from '@/api/opposite'
import Cookies from 'js-cookie'//获取cookies的信息

export default {
    props: ['type', "listid"],
    name: 'UnitTable',
    components: {
        TableTop,
    },
    data() {
        return {
            form: {
                name: ""
            },
            dialogFormVisible: false,
            emtypetxt: "",
            // 相对方企业请求参数
            params: {
                contactsEnterpriseName: "",//联系人公司名称
                contactsName: "",//联系人名称
                contactsPhone: "",//联系人电话
                contractId: "",//合同id
                enterpriseId: "",//企业id
                hasEnterprise: "",//是否有企业
                id: "",//常用联系人id
                insertTime: "",//申请时间
                isAuth: "",//是否认证 0 否 1是
                isHide: "",//删除标识 0-否 1-是
                keywordsTxt: "",//关键字搜索key
                // type: 0,//联系人类型 0-个人 1-企业
                userId: Cookies.get('admin_id'),//用户id//获取cookies中用户id的信息
                pageNo: 1,
                pageSize: 10
            },
            list: [],
            total: 0,
        };
    },
    mounted() {
        if (this.$route.query.id) {
            this.params.id = this.$route.query.id
        }
        this.$bus.$off('getPersonsearch')
        this.$bus.$on("getPersonsearch", data => {
            this.params.contactsName = data.contactsName
            this.params.contactsPhone = data.contactsPhone
            this.params.isAuth = data.isAuth
            this.getList()
            return false
        })
        this.getList()
    },
    methods: {
        getList() {
            this.emtypetxt = '加载中...';
            oppositeListDetail(this.params).then(res => {
                this.list = res.result.records
                this.total = res.result.total
                if (this.list.length == 0) {
                    this.emtypetxt = '暂无数据'
                }
            }).catch(err => {
                console.log("请求失败", err)
            })
        },
        // 跳转个人详情
        handleClick(item) {
            this.$router.push({ name: 'unitDetail', query: { id: item.contactsId } },()=>{})
        },
        // 删除
        edit() {
            this.$confirm('确定删除刘贞贞？', '删除', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },

        handleSizeChange(val) {
            this.params.pagesize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.params.pageNo = val
            this.getList()
        },

        handleSelectionChange(val) {
            this.multipleSelection = val;
        }
    }

}
</script>

<style></style>